<?php
namespace Admin\Controller;
use Think\Controller;

class LoginController extends Controller {
    //登陆主页
    public function index(){
        $this->display();
    }
    //登陆验证
    public function login(){
       
        $admin=D('Admin');
        if(!$_POST['username']){
                    $this->error('用户名不能为空');
        }
        if(!$_POST['password']){
                    $this->error('密码不能为空');
        }
        if(!$_POST['verify']){
                    $this->error('验证码不能为空');
        }
            
        $verify = new \Think\Verify();
        if(!$verify->check($_POST['verify'])){
                $this -> error('验证码错误',U('Login/index'));
         }
        if($admin->login($_POST['username'],$_POST['password'])){
                $this->success('登录中...',U('index/index'));
        }else{
                $this->error('用户名或密码错误！');
        }
        
    }
    //验证码
    public function verify(){
        $Verify = new \Think\Verify();
        $Verify->codeSet = '0123456789';
        $Verify->fontSize = 13;
        $Verify->length = 4;
        $Verify->entry();
    }
    protected function check_verify($code){
        $verify = new \Think\Verify();
        return $verify->check($code);
    }

    public function logout(){
    session(null);
    $this->success('退出成功！',U('Login/index'));
   }
}